﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace MethodWorx.CMS.TemplateParser.Tests
{
    [TestClass]
    public class TemplateFlattenerTests
    {
        [TestMethod]
        public void TestFlattenSingleTemplate()
        {
            string template1 = "<element><placeholder type=\"container\" name=\"body\"></placeholder></element>";
            string template2 = "<placeholder type=\"content\" name=\"body\">Some Content</placeholder>";

            var flattener = new TemplateFlattener(template1, template2);

            Assert.AreEqual("<element>Some Content</element>", flattener.Parser.Document.OuterXml);
        }

        [TestMethod]
        public void TestFlattenMultipleSingleTemplate()
        {
            string template1 = "<element><placeholder type=\"container\" name=\"body\"></placeholder></element>";
            string template2 = "<placeholder type=\"content\" name=\"body\">Some<placeholder type=\"container\" name=\"content\"></placeholder>Content</placeholder>";
            string template3 = "<placeholder type=\"content\" name=\"content\"><more></more></placeholder>";

            var flattener = new TemplateFlattener(template1, template2, template3);

            Assert.AreEqual("<element>Some<more></more>Content</element>", flattener.Parser.Document.OuterXml);
        }

        [TestMethod]
        public void TestFlattenMultiplePlaceholders()
        {
            string template1 = "<element><placeholder type=\"container\" name=\"body1\"></placeholder><placeholder type=\"container\" name=\"body2\"></placeholder></element>";
            string template2 = "<placeholder type=\"content\" name=\"body1\">Some Content</placeholder><placeholder type=\"content\" name=\"body2\">Some Content</placeholder>";

            var flattener = new TemplateFlattener(template1, template2);

            Assert.AreEqual("<element>Some ContentSome Content</element>", flattener.Parser.Document.OuterXml);
        }

        [TestMethod]
        public void TestFlattenMultipleSingleTemplateWithAttributes()
        {
            string template1 = "<element a=\"b\"><placeholder type=\"container\" name=\"body\"></placeholder></element>";
            string template2 = "<placeholder type=\"content\" name=\"body\">Some<placeholder type=\"container\" name=\"content\"></placeholder>Content</placeholder>";
            string template3 = "<placeholder type=\"content\" name=\"content\"><more a=\"b\" b=\"c\"></more></placeholder>";

            var flattener = new TemplateFlattener(template1, template2, template3);

            Assert.AreEqual("<element a=\"b\">Some<more a=\"b\" b=\"c\"></more>Content</element>", flattener.Parser.Document.OuterXml);
        }
    }
}
